package by.hqsoftware.RollingBall;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import java.util.ArrayList;

public abstract class Converter {

	public static FloatBuffer toBuffer(float[] source) {
    	// a float is 4 bytes, therefore we multiply the number if
    	// vertices with 4.
    	ByteBuffer vbb = ByteBuffer.allocateDirect(source.length * 4);
    	vbb.order(ByteOrder.nativeOrder());
    	FloatBuffer buffer = vbb.asFloatBuffer();
    	buffer.put(source);
    	buffer.position(0);
    	return buffer;
	}
	
	public static ShortBuffer toBuffer(short[] source) {
    	// short is 2 bytes, therefore we multiply the number if
    	// vertices with 2.
    	ByteBuffer ibb = ByteBuffer.allocateDirect(source.length * 2);
    	ibb.order(ByteOrder.nativeOrder());
    	ShortBuffer buffer = ibb.asShortBuffer();
    	buffer.put(source);
    	buffer.position(0);
    	return buffer;
    }
	
	public static float[] ToFloatArray(ArrayList<Float> source) {    	
    	float[] target = new float[source.size()];
		for (int i = 0; i < source.size(); i++) {
			target[i] = source.get(i);
		}
		return target;
    }
    
    public static short[] ToShortArray(ArrayList<Short> source) {    	
    	short[] target = new short[source.size()];
		for (int i = 0; i < source.size(); i++) {
			target[i] = source.get(i);
		}
		return target;
    }
}
